package cn.itheima.taotao.content.service.impl;

import cn.itheima.taotao.content.service.ContentCategorytService;
import cn.itheima.taotao.domain.ContentCategory;
import cn.itheima.taotao.domain.ContentCategoryExample;
import cn.itheima.taotao.domain.EasyUITreeNode;
import cn.itheima.taotao.mapper.ContentCategoryMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator .
 */
@Service
public class ContentCategorytServiceImpl implements ContentCategorytService {

    @Resource
    private ContentCategoryMapper contentCategoryMapper;

    @Override
    public List<EasyUITreeNode> getContentCatList(long parentId) {
        ContentCategoryExample contentCategoryExample = new ContentCategoryExample();
        List<ContentCategory> contentCategories = contentCategoryMapper.selectByExample(contentCategoryExample);
        List<EasyUITreeNode> easyUITreeNodes = new ArrayList<>();
        for (ContentCategory contentCategory : contentCategories) {
            EasyUITreeNode easyUITreeNode = new EasyUITreeNode();
            easyUITreeNode.setId(contentCategory.getId());
            easyUITreeNode.setText(contentCategory.getName());
            easyUITreeNode.setState(contentCategory.getIsParent() ? "closed" : "open");
            easyUITreeNodes.add(easyUITreeNode);
        }
        return easyUITreeNodes;
    }
}
